//
//  HTTPJSONBody.swift
//
//
//  Created by czi on 2023/12/7.
//

import Foundation

public protocol HTTPJSONBody {
    func asJSONData() -> Data?
}

public extension HTTPJSONBody where Self: Encodable {
    func asJSONData() -> Data? {
        let encoder = JSONEncoder()
        encoder.outputFormatting = .sortedKeys
        return try? encoder.encode(self)
    }
}
